/**
 * 掉落盒子脚本，实现盒子碰撞及回收流程
 */
export default class Box extends Laya.Script {
    /**刚体对象引用 */
    private _rig: Laya.RigidBody;

    /** @prop {name:box1,tips:"掉落容器预制体对象1",type:Prefab}*/
    box1: Laya.Prefab;
    private _box1: Laya.Sprite;

    /** @prop {name:box2,tips:"掉落容器预制体对象1",type:Prefab}*/
    box2: Laya.Prefab;
    private _box2: Laya.Sprite;

    /** @prop {name:box3,tips:"掉落容器预制体对象1",type:Prefab}*/
    box3: Laya.Prefab;
    private _box3: Laya.Sprite;

    constructor() { super(); }

    onEnable(): void {
       
    }

    onUpdate(): void {
       
    }

    creatBox(boxLevel: number): Laya.Sprite{
        let currentBox: Laya.Sprite;
        if(boxLevel === 1){
            this._box1 = Laya.Pool.getItemByCreateFun("box1", this.box1.create, this.box1);
            currentBox = this._box1;
        }else if(boxLevel === 2){
            this._box2 = Laya.Pool.getItemByCreateFun("box2", this.box2.create, this.box2);
            currentBox = this._box2;
        }else if(boxLevel === 3){
            this._box3 = Laya.Pool.getItemByCreateFun("box3", this.box3.create, this.box3);
            currentBox = this._box3;
        }
        
        return currentBox;
    }

    onTriggerEnter(other: any, self: any, contact: any): void {
       
    }

    onDisable(): void {
        //盒子被移除时，回收盒子到对象池，方便下次复用，减少对象创建开销。
        Laya.Pool.recover("box", this.owner);
    }
}